﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Configuration;
using System.Data.SqlClient;

namespace BHair.xitong
{
    public partial class frmxiangmupipei : Form
    {
        public frmxiangmupipei()
        {
            InitializeComponent();
        }
        string constr = ConfigurationManager.ConnectionStrings["BHair.Properties.Settings.BHairDBConnectionString"].ConnectionString;
        private void button1_Click(object sender, EventArgs e)
        {
            SqlConnection conn = new SqlConnection(constr);
            conn.Open();
            SqlConnection conn1 = new SqlConnection(constr);
            conn1.Open();
            string sql = "SELECT  [iid] ,[iname] FROM [items]";
            //循环查询项目的名称对应的ID
            SqlCommand comm = new SqlCommand(sql,conn);
            SqlDataReader sdr = comm.ExecuteReader();
            while (sdr.Read())
            {
                string xmid = sdr["iid"].ToString();
                string xmname = sdr["iname"].ToString();
                string sql2 = string.Format("UPDATE [csmx] SET [jcxmname] = '{0}' WHERE jcspid='{1}'",xmname,xmid);
                SqlCommand comm2 = new SqlCommand(sql2,conn1);
                comm2.ExecuteNonQuery();
            }
            conn.Close();
            conn1.Close();
            MessageBox.Show("比对成功");
        }

        private void button2_Click(object sender, EventArgs e)
        {
            SqlConnection conn = new SqlConnection(constr);
            conn.Open();
            SqlConnection conn1 = new SqlConnection(constr);
            conn1.Open();
            //循环查询会员积分
            string sql_cx = "select mid,积分 from member";
            SqlCommand commcx = new SqlCommand(sql_cx,conn);
            SqlDataReader sdr = commcx.ExecuteReader();
            while (sdr.Read())
            {
                string mid = sdr["mid"].ToString();
                decimal jf =decimal.Parse( sdr["积分"].ToString());
                //循环修改累计积分
                string sql_up =string.Format( "update member set 累计积分='{0}' where mid='{1}'",jf,mid);
                SqlCommand comm = new SqlCommand(sql_up,conn1);
                comm.ExecuteNonQuery();
            }
            conn.Close();
            conn1.Close();
            MessageBox.Show("ok");
        }
    }
}
